﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.ScriptEngine.Custom
{
    internal class OutputWriter : System.IO.TextWriter
    {
        private Action<string, bool> _action;

        public OutputWriter(Action<string, bool> action)
        {
            _action = action;
        }

        public override void Write(string value)
        {
            if (_action != null)
            {
                _action(value, false);
            }
        }

        public override void WriteLine(string value)
        {
            if (_action != null)
            {
                _action(value, true);
            }
        }

        public override System.Text.Encoding Encoding
        {
            get { return System.Text.Encoding.UTF8; }
        }
    }
}
